﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace TestStudentsAndCourses
{
    [TestClass()]
    public class CourseTest
    {
        [TestMethod()]
        public void CourseConstructorTest()
        {
            Course target = new Course();
            Assert.AreNotEqual(target, null, "Constructor fail");
            Assert.AreEqual(target.StudentsCount, 0);
        }

        [TestMethod()]
        public void CourseConstructorTest1()
        {
            Student st1 = new Student("pe6o", 11111);
            Student st2 = new Student("go6o", 11112);
            HashSet<Student> course = new HashSet<Student>() {st1, st2};
            Course target = new Course(course);
            Assert.AreEqual(target.StudentsCount, 2, "Wrong number of students");
            Assert.AreNotSame(target[0], st1, "target[0] is the same as st1");
            Assert.AreNotSame(target[1], st2, "target[1] is the same as st2");
            Assert.AreEqual(target[0], new Student("s", 11111));
            Assert.AreEqual(target[1], new Student("s", 11112));     
        }

        [TestMethod()]
        public void AddStudentTest()
        {
            Course target = new Course();
            Student st = new Student("someName", 11001);
            bool expected = true;
            bool actual;
            actual = target.AddStudent(st);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void RemoveStudentTest()
        {
            Course target = new Course();
            Student st1 = new Student("someName", 11001);
            target.AddStudent(st1);
            bool expected = true;
            bool actual;
            actual = target.RemoveStudent(new Student("ss", 11001));
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void AddExistingStudentTest()
        {
            Course target = new Course();
            Student st = new Student("someName", 11001);
            target.AddStudent(st);
            target.AddStudent(st);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void RemoveNotExistingStudentTest()
        {
            Course target = new Course();
            Student st = new Student("someName", 11001);
            target.RemoveStudent(new Student("someName", 11000));
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void RemoveNullStudentTest()
        {
            Course target = new Course();
            Student st = null;
            target.RemoveStudent(st);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void InvalidIndexInCourseTest()
        {
            Course target = new Course();
            Student st = new Student("someName", 11111);
            target.AddStudent(st);
            st = target[1];
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void NegativeIndexInCourseTest()
        {
            Course target = new Course();
            Student st = new Student("someName", 11111);
            target.AddStudent(st);
            st = target[-12];
        }

        [TestMethod()]
        public void AddMoreThan30StudentsTest()
        {
            Course target = new Course();
            for (int i = 1; i < 40; i++)
            {
                if (!target.AddStudent(new Student("someName", 10000 + i)))
                {
                    Assert.AreEqual(i, 31);
                    break;
                }
            }
        }
    }
}
